package com.lgc.eventsounds;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JCheckBox;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JPanel;

public class EventSoundsConfiguration {
  private JCheckBox _breakpointSoundEnabledCB;
  private JCheckBox _buildErrorSoundEnabledCB;
  private JCheckBox _buildSuccessSoundEnabledCB;
  private JCheckBox _buildWarningSoundEnabledCB;
  private JCheckBox _exceptionSoundEnabledCB;
  private JCheckBox _findFailedSoundEnabledCB;
  private JCheckBox _findSuccessSoundEnabledCB;
  private JCheckBox _processStoppedSoundEnabledCB;
  private JTextField _breakpointSoundTF;
  private JTextField _buildErrorSoundTF;
  private JTextField _buildSuccessSoundTF;
  private JTextField _buildWarningSoundTF;
  private JTextField _exceptionSoundTF;
  private JTextField _findFailedSoundTF;
  private JTextField _findSuccessSoundTF;
  private JTextField _processStoppedSoundTF;
  private JButton _defaultBreakpointSoundB;
  private JButton _defaultBuildErrorSoundB;
  private JButton _defaultBuildSuccessSoundB;
  private JButton _defaultBuildWarningSoundB;
  private JButton _defaultExceptionSoundB;
  private JButton _defaultFindFailedSoundB;
  private JButton _defaultFindSuccessSoundB;
  private JButton _defaultProcessStoppedSoundB;
  private JPanel _mainPanel;

  public EventSoundsConfiguration()
  {
    _defaultBreakpointSoundB.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent)
      {
        _breakpointSoundTF.setText(EventSoundsProjectComponent.DEFAULT_BREAKPOINT_SOUND);
      }
    });
    _defaultBuildErrorSoundB.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent)
      {
        _buildErrorSoundTF.setText(EventSoundsProjectComponent.DEFAULT_BUILD_ERROR_SOUND);
      }
    });
    _defaultBuildSuccessSoundB.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent)
      {
        _buildSuccessSoundTF.setText(EventSoundsProjectComponent.DEFAULT_BUILD_SUCCESS_SOUND);
      }
    });
    _defaultBuildWarningSoundB.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent)
      {
        _buildWarningSoundTF.setText(EventSoundsProjectComponent.DEFAULT_BUILD_WARNING_SOUND);
      }
    });
    _defaultExceptionSoundB.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent)
      {
        _exceptionSoundTF.setText(EventSoundsProjectComponent.DEFAULT_EXCEPTION_SOUND);
      }
    });
    _defaultFindFailedSoundB.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent)
      {
        _findFailedSoundTF.setText(EventSoundsProjectComponent.DEFAULT_FIND_FAILED_SOUND);
      }
    });
    _defaultFindSuccessSoundB.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent)
      {
        _findSuccessSoundTF.setText(EventSoundsProjectComponent.DEFAULT_FIND_SUCCESS_SOUND);
      }
    });
    _defaultProcessStoppedSoundB.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent)
      {
        _processStoppedSoundTF.setText(EventSoundsProjectComponent.DEFAULT_PROCESS_STOPPED_SOUND);
      }
    });
  }

  public JPanel get_mainPanel()
  {
    return(_mainPanel);
  }

  public void set_mainPanel(JPanel mainPanel)
  {
    _mainPanel = mainPanel;
  }

  public void setData(EventSoundsProjectComponent data)
  {
    _breakpointSoundEnabledCB.setSelected(data.is_breakpointSoundEnabled());
    _buildErrorSoundEnabledCB.setSelected(data.is_buildErrorSoundEnabled());
    _buildSuccessSoundEnabledCB.setSelected(data.is_buildSuccessSoundEnabled());
    _buildWarningSoundEnabledCB.setSelected(data.is_buildWarningSoundEnabled());
    _exceptionSoundEnabledCB.setSelected(data.is_exceptionSoundEnabled());
    _findFailedSoundEnabledCB.setSelected(data.is_findFailedSoundEnabled());
    _findSuccessSoundEnabledCB.setSelected(data.is_findSuccessSoundEnabled());
    _processStoppedSoundEnabledCB.setSelected(data.is_processStoppedSoundEnabled());
    _breakpointSoundTF.setText(data.get_breakpointSound());
    _buildErrorSoundTF.setText(data.get_buildErrorSound());
    _buildSuccessSoundTF.setText(data.get_buildSuccessSound());
    _buildWarningSoundTF.setText(data.get_buildWarningSound());
    _exceptionSoundTF.setText(data.get_exceptionSound());
    _findFailedSoundTF.setText(data.get_findFailedSound());
    _findSuccessSoundTF.setText(data.get_findSuccessSound());
    _processStoppedSoundTF.setText(data.get_processStoppedSound());
  }

  public void getData(EventSoundsProjectComponent data)
  {
    data.set_breakpointSoundEnabled(_breakpointSoundEnabledCB.isSelected());
    data.set_buildErrorSoundEnabled(_buildErrorSoundEnabledCB.isSelected());
    data.set_buildSuccessSoundEnabled(_buildSuccessSoundEnabledCB.isSelected());
    data.set_buildWarningSoundEnabled(_buildWarningSoundEnabledCB.isSelected());
    data.set_exceptionSoundEnabled(_exceptionSoundEnabledCB.isSelected());
    data.set_findFailedSoundEnabled(_findFailedSoundEnabledCB.isSelected());
    data.set_findSuccessSoundEnabled(_findSuccessSoundEnabledCB.isSelected());
    data.set_processStoppedSoundEnabled(_processStoppedSoundEnabledCB.isSelected());
    data.set_breakpointSound(_breakpointSoundTF.getText());
    data.set_buildErrorSound(_buildErrorSoundTF.getText());
    data.set_buildSuccessSound(_buildSuccessSoundTF.getText());
    data.set_buildWarningSound(_buildWarningSoundTF.getText());
    data.set_exceptionSound(_exceptionSoundTF.getText());
    data.set_findFailedSound(_findFailedSoundTF.getText());
    data.set_findSuccessSound(_findSuccessSoundTF.getText());
    data.set_processStoppedSound(_processStoppedSoundTF.getText());
  }

  public boolean isModified(EventSoundsProjectComponent data)
  {
    if(_breakpointSoundEnabledCB.isSelected() != data.is_breakpointSoundEnabled())
      return(true);
    if(_buildErrorSoundEnabledCB.isSelected() != data.is_buildErrorSoundEnabled())
      return(true);
    if(_buildSuccessSoundEnabledCB.isSelected() != data.is_buildSuccessSoundEnabled())
      return(true);
    if(_buildWarningSoundEnabledCB.isSelected() != data.is_buildWarningSoundEnabled())
      return(true);
    if(_exceptionSoundEnabledCB.isSelected() != data.is_exceptionSoundEnabled())
      return(true);
    if(_findFailedSoundEnabledCB.isSelected() != data.is_findFailedSoundEnabled())
      return(true);
    if(_findSuccessSoundEnabledCB.isSelected() != data.is_findSuccessSoundEnabled())
      return(true);
    if(_processStoppedSoundEnabledCB.isSelected() != data.is_processStoppedSoundEnabled())
      return(true);
    if(_breakpointSoundTF.getText() != null ? !_breakpointSoundTF.getText().equals(data.get_breakpointSound()) : data.get_breakpointSound() != null)
      return(true);
    if(_buildErrorSoundTF.getText() != null ? !_buildErrorSoundTF.getText().equals(data.get_buildErrorSound()) : data.get_buildErrorSound() != null)
      return(true);
    if(_buildSuccessSoundTF.getText() != null ? !_buildSuccessSoundTF.getText().equals(data.get_buildSuccessSound()) : data.get_buildSuccessSound() != null)
      return(true);
    if(_buildWarningSoundTF.getText() != null ? !_buildWarningSoundTF.getText().equals(data.get_buildWarningSound()) : data.get_buildWarningSound() != null)
      return(true);
    if(_exceptionSoundTF.getText() != null ? !_exceptionSoundTF.getText().equals(data.get_exceptionSound()) : data.get_exceptionSound() != null)
      return(true);
    if(_findFailedSoundTF.getText() != null ? !_findFailedSoundTF.getText().equals(data.get_findFailedSound()) : data.get_findFailedSound() != null)
      return(true);
    if(_findSuccessSoundTF.getText() != null ? !_findSuccessSoundTF.getText().equals(data.get_findSuccessSound()) : data.get_findSuccessSound() != null)
      return(true);
    if(_processStoppedSoundTF.getText() != null ? !_processStoppedSoundTF.getText().equals(data.get_processStoppedSound()) : data.get_processStoppedSound() != null)
      return(true);
    return(false);
  }
}
